package org.jeecg.modules.appuser.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.util.Date.DateUtil;
import org.jeecg.modules.appuser.entity.TbUserIntegralConfig;
import org.jeecg.modules.appuser.mapper.TbUserIntegralConfigMapper;
import org.jeecg.modules.appuser.service.ITbUserIntegralConfigService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 积分奖励配置表	
 * @Author: jeecg-boot
 * @Date:   2020-05-19
 * @Version: V1.0
 */
@Service
public class TbUserIntegralConfigServiceImpl extends ServiceImpl<TbUserIntegralConfigMapper, TbUserIntegralConfig> implements ITbUserIntegralConfigService {

    @Override
    public TbUserIntegralConfig getOneByName(String taskName) {
        QueryWrapper  queryWrapper=new QueryWrapper();
        queryWrapper.eq("task_name",taskName);
        return getOne(queryWrapper);
    }

    @Override
    public TbUserIntegralConfig getTodayTaskByName(String taskName, String user_id) {

        QueryWrapper  queryWrapper=new QueryWrapper();
        queryWrapper.eq("task_name",taskName);
        queryWrapper.eq("user_id",user_id);
        queryWrapper.ge("create_time", DateUtil.calcDate(0));
        queryWrapper.le("end_time",  DateUtil.calcDate(1));
        return   getOne(queryWrapper);

    }

    @Override
    public List<TbUserIntegralConfig> getInitConfigList() {

        QueryWrapper  queryWrapper=new QueryWrapper();
        queryWrapper.eq("state",1);
        queryWrapper.eq("init_state",1);
        queryWrapper.orderByAsc("sort");
        return list(queryWrapper);
    }
}
